let timer;
let last;
const utils = {
	/**
	 * 获取主题颜色
	 * black white
	 */
	getBC() {
		// ZTBG主题颜色
		let code = uni.getStorageSync("ZTBG") || ""
		if (!code || code == 'black') {
			// 默认是黑色
			uni.setStorageSync("ZTBG", 'black')
			return {
				bg: "black",
				cl: "white"
			}
		} else if (code == "white") {
			// 白色
			return {
				bg: "white",
				cl: "black"
			}
		}

	},

	/**
	 * showTost
	 * title:提示标题，icon
	 */
	showTost(title, icon) {
		uni.showToast({
			title: title,
			icon: icon || "none",
			duration: 2000
		})
	},
	throttle(fn, wait) {
		return function() {
			let th = this;
			let args = arguments;
			let now = +new Date();
			if (last && (now - last) < wait) {
				clearTimeout(timer);
				timer = setTimeout(() => {
					last = now;
					fn.apply(th, args);
				}, wait);
			} else {
				last = now;
				fn.apply(th, args);
			}
		};
	},


}
export default utils